#define _GNU_SOURCE
#include <sched.h>
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <time.h>

//#include <sys/mman.h>
#include <sys/time.h>
#include <unistd.h>

#include <semaphore.h>
#include <pthread.h>


#include <signal.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdint.h>
#include <ctype.h>

#include <unistd.h>
//#include <sys/syscall.h>

#define ONE_SEC_NS (1000000000ULL)
#define PERIODIC_NS (10000000ULL)
#define COUNT_NUM 40000000

static int64_t current_time_ns(void) {
    struct timespec ts;
    clock_gettime(CLOCK_REALTIME, &ts);
    return ts.tv_sec * ONE_SEC_NS + ts.tv_nsec;
}

int main()
{
    volatile long count = COUNT_NUM;
    long start_time = current_time_ns();

    while (count--)
    {
        __asm__ volatile("mov r0,r0":::"r0");
    }
    
    long end_time = current_time_ns();

    long first_time = end_time - start_time;

    count = COUNT_NUM;
    start_time = current_time_ns();
    while (count--)
    {
        __asm__ volatile("mov r0,r0":::"r0");
        __asm__ volatile("mov r0,r0":::"r0");
    }
    end_time = current_time_ns();

    long second_time = end_time - start_time;

    printf("the HZ Fuction time cost is %ld\n", (second_time - first_time));
   
}
